const os = require( 'os' )
const cpus = os.cpus()

// 获取 cpu 信息
console.log( cpus.length, 'cpus' )


function getGb( bytes ){
  const kb = ( bytes / 1024 ).toFixed( 2 );
  const mb = ( kb / 1024 ).toFixed( 2 );
  return ( mb / 1024 ).toFixed( 2 )
}

// 获取内存大小
const total = os.totalmem(); // bytes
const totalGb = getGb( total );
console.log( totalGb, 'totalGb' );

const free = os.freemem();
const freeGb = getGb( free );
console.log( freeGb, 'freeGb' );